System and method for providing code completion features for code modules

ABSTRACT

Systems and methods are described for providing code completion features for code modules that have been incorporated into a source code document being edited by a user of a source code editor. Embodiment dynamically load and apply partial code evaluation to code modules referenced in the source code document (and any code modules referenced directly or indirectly by such code modules) while the user is editing it. The partial code evaluation is performed on a background thread that is separate from a main thread used to execute the user interface for the source code editor. The results of such partial code evaluation are cached and used to provide code completion information for the code modules.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of U.S. patent application Ser. No.13/909,758, filed Jun. 4, 2013 (now U.S. Pat. No. 9,471,286, issued Oct.18, 2016), the entirety of which is incorporated by reference herein.

BACKGROUND

Software development environments exist that aid software developers inwriting program code. A software development environment may include asource code editor for entering source code, one or more buildautomation tools, and a code debugger. Examples ofcommercially-available software development environments includeMicrosoft® WebMatrix® and Microsoft® Visual Studio®, provided byMicrosoft Corporation of Redmond, Wash., JDeveloper® and NetBeans®,provided by Oracle Corporation of Redwood City, Calif., Adobe®Dreamweaver®, provided by Adobe Systems Inc. of San Jose, Calif.,Eclipse IDE provided by Eclipse Foundation of Ontario, Canada,ActiveState® Komodo® provided by ActiveState Software Inc. of Vancouver,British Columbia, and IntelliJ® IDEA, provided by JetBrains, s.r.o., ofPrague, Czech Republic.

Some conventional software development environments provide assistanceto developers writing code by presenting what are known as codecompletion features. Code completion features are features that helpdevelopers learn more about the code they are using, keep track ofparameters they are typing, and add calls to properties and methods withonly a few keystrokes. For example, providing a code completion featuremay involve automatically displaying a list of valid members from a type(or namespace) after a developer types a trigger character (for example,a period (.) in managed code or :: in C++) within a source code file. Byinteracting with an item within the list, a developer may cause the itemto be automatically inserted into the source code file or may receiveadditional information about the item (e.g., a complete declaration forthe item). Providing a code completion feature may also involveautomatically providing a developer with information about the number,names, and types of parameters required by a method, or automaticallycompleting the rest of a variable, command, or function name once adeveloper has entered enough characters to disambiguate the term. InMicrosoft® WebMatrix® and Microsoft® Visual Studio®, the code completionfeatures are referred to as IntelliSense®.

In providing code completion features, the degree of accuracy that canbe achieved may depend on the type of programming language being used.For strongly typed languages such as Visual Basic and C#, providingaccurate code completion information is relatively straightforward. Forexample, simple token-based analysis and/or static code analysis of thesource code file may be used to provide highly-accurate code completioninformation for strongly typed programming languages. In contrast, itcan be difficult to provide accurate code completion information fordynamic languages such as JavaScript, PHP, and Python, since theselanguages do not provide a consistent object model. For such dynamicprogramming languages, it can be difficult to correctly infer the shapeand structure of variables, methods and the like, since these entitiesmay be modified at runtime.

Programming platforms exist that enable developers to incorporate codemodules that are stored in one or more support libraries into theirsource code files. For example, developers working in node.js—a popularserver-side programming platform designed for writing scalable Internetapplications—can incorporate the functionality of JavaScript codemodules known as “node packaged modules” (also referred to herein as“node.js modules”) by simply referencing such modules in their sourcecode files. Using these modules can be painful for a developer becausemany source code editors do not provide functionality that shows thedeveloper how to use the module application programming interface (API).Consequently, to determine how the module works, the developer musteither try to find public documentation about the module or, if no suchdocumentation exists, read the source code of the module itself.

SUMMARY

This Summary is provided to introduce a selection of concepts in asimplified form that are further described below in the DetailedDescription. This Summary is not intended to identify key features oressential features of the claimed subject matter, nor is it intended tobe used to limit the scope of the claimed subject matter. Moreover, itis noted that the claimed subject matter is not limited to the specificembodiments described in the Detailed Description and/or other sectionsof this document. Such embodiments are presented herein for illustrativepurposes only. Additional embodiments will be apparent to personsskilled in the relevant art(s) based on the teachings contained herein.

A method for providing code completion features for a source codedocument being edited by a user of a source code editor is describedherein. In accordance with the method, a determination is made that codecompletion information is required for at least one code entityassociated with a first code module referenced in the source codedocument. The first code module may comprise, for example, a code modulewritten in a dynamic programming language such as a node.js module. Inresponse to the determination, a number of steps are performed. Inparticular, module code is loaded. The module code includes code of thefirst code module. The module code may also include code of one or moreadditional code modules referenced directly or indirectly by the firstcode module. The module code is executed in a partial code evaluator togenerate partial code evaluation results. The code completioninformation is derived from the partial code evaluation results. Then,the code completion information is provided to the user of the sourcecode editor.

In accordance with the foregoing method, loading the module code mayinclude determining a location of a file that stores at least a portionof the first code module based on rules associated with a runtimeenvironment.

In further accordance with the foregoing method, executing the modulecode in the partial code evaluator may include building an abstractsyntax tree based upon the module code and evaluating nodes of theabstract syntax tree in the partial code evaluator.

The foregoing method may further include caching the partial codeevaluation results. For example, the partial code evaluation results maybe cached in one or more of volatile and non-volatile memory. Inaccordance with such an embodiment, the step of deriving the codecompletion information may include deriving the code completioninformation from the cached partial code evaluation results. In furtheraccordance with such an embodiment, the method may further includeclearing the cached partial code evaluation results in response todetermining that a file that stores at least a portion of the first codemodule has changed. In still further accordance with such an embodiment,the method may further include utilizing the cached partial codeevaluation results to derive code completion information for a secondsource code document.

In one embodiment of the foregoing method, the step of executing themodule code in the partial code evaluator is executed on a backgroundthread that is separate from a main thread upon which an interface forthe source code editor is executed.

In another embodiment of the foregoing method, the method furtherincludes providing code completion information to the user of the sourcecode editor that is based upon one or more default values rather thanupon the partial code evaluation results while the module code is beingexecuted in the partial code evaluator.

A computer program product is also described herein. The computerprogram product comprises a computer readable storage device havingcomputer program logic recorded thereon for enabling a processing unitto provide code completion features for a source code document beingedited by a user of a source code editor. The computer program logicincludes first computer program logic and second computer program logic.When executed by the processing unit, the first computer program logicdetermines that code completion information is to be obtained for atleast one code entity associated with a code module referenced in thesource code document. The code module may comprise, for example, a codemodule written in a dynamic programming language such as a node.jsmodule. When executed by the processing unit, the second computerprogram logic performs the following in response to the determination:loads partial code evaluation results obtained by pre-applying partialcode evaluation to code of the code module, derives the code completioninformation from the partial code evaluation results, and provides thecode completion information to the user of the source code editor.

A system is also described herein. The system includes one or moreprocessors and a storage medium that stores computer program logic thatis executable by the one or more processors. The computer program logicincludes a code completion engine and a programming language engine. Inresponse to a determination that code completion information is to beobtained for at least one code entity associated with a first codemodule referenced in the source code document, the programming languageengine determines whether the first code module is a core module or acustom module. If the programming language engine determines that thefirst code module is a core module, then the programming language engineobtains from a module loader partial code evaluation results obtained bypre-applying partial code evaluation to code of the first code module,and derives the code completion information from the partial codeevaluation results obtained by pre-applying partial code evaluation tocode of the first code module. If the programming language enginedetermines that the first code module is a custom module, then theprogramming language engine obtains from the module loader module code,the module code including code of the first code module, executes themodule code in a partial code evaluator to generate partial codeevaluation results, and derives the code completion information from thepartial code evaluation results obtained by executing the module code inthe partial code evaluator. The code completion engine provides the codecompletion information to the user of the source code editor.

In one embodiment of the foregoing system, the first code modulecomprises a code module written in a dynamic programming language suchas a node.js module.

In another embodiment of the foregoing system, the module code comprisescode of the first code module and code of one or more additional codemodules referenced directly or indirectly by the first code module.

In yet another embodiment of the foregoing system, the system alsoincludes a cache that caches the partial code evaluation resultsobtained by executing the module code in the partial code evaluator.

BRIEF DESCRIPTION OF THE DRAWINGS/FIGURES

The accompanying drawings, which are incorporated herein and form partof the specification, illustrate embodiments of the present inventionand, together with the description, further serve to explain theprinciples of the invention and to enable a person skilled in therelevant art(s) to make and use the invention.

FIG. 1 is a block diagram of a system that provides code completionfeatures for a code module referenced by a source code document inaccordance with an embodiment.

FIG. 2 depicts a flowchart of a method for providing code completionfeatures for a code module referenced by a source code document inaccordance with an embodiment.

FIG. 3 depicts a flowchart of a method for performing partial codeevaluation in accordance with an embodiment.

FIG. 4 is a block diagram of an example processor-based computer systemthat may be used to implement various embodiments.

The features and advantages of the present invention will become moreapparent from the detailed description set forth below when taken inconjunction with the drawings, in which like reference charactersidentify corresponding elements throughout. In the drawings, likereference numbers generally indicate identical, functionally similar,and/or structurally similar elements. The drawing in which an elementfirst appears is indicated by the leftmost digit(s) in the correspondingreference number.

DETAILED DESCRIPTION I. Introduction

The following detailed description refers to the accompanying drawingsthat illustrate exemplary embodiments of the present invention. However,the scope of the present invention is not limited to these embodiments,but is instead defined by the appended claims. Thus, embodiments beyondthose shown in the accompanying drawings, such as modified versions ofthe illustrated embodiments, may nevertheless be encompassed by thepresent invention.

References in the specification to “one embodiment,” “an embodiment,”“an example embodiment,” or the like, indicate that the embodimentdescribed may include a particular feature, structure, orcharacteristic, but every embodiment may not necessarily include theparticular feature, structure, or characteristic. Moreover, such phrasesare not necessarily referring to the same embodiment. Furthermore, whena particular feature, structure, or characteristic is described inconnection with an embodiment, it is submitted that it is within theknowledge of persons skilled in the relevant art(s) to implement suchfeature, structure, or characteristic in connection with otherembodiments whether or not explicitly described.

Embodiments described herein enable code completion features to beprovided for code modules that have been incorporated into a source codedocument being edited by a user of a source code editor. Such codemodules may include, for example, code modules programmed in a dynamicprogramming language such as JavaScript. In further accordance with thisexample, such code modules may include node.js modules associated withthe popular node.js programming platform. However, this is an exampleonly, and persons skilled in the relevant art(s) will readily appreciatethat the techniques described herein may be used to provide codecompletion features for any type of code module incorporated into asource code document, including but not limited to code modules writtenin dynamically typed languages that are incorporated into source codedocuments.

As discussed above in the Background Section, using code modules such asnode.js modules can be painful for a developer because many source codeeditors do not provide functionality that shows the developer how to usethe module API. Embodiments described herein address this issue byproviding an array of code completion features that can assist adeveloper in understanding code entities (e.g., methods and datamembers) associated with a code module that the developer hasincorporated into his/her source code. As will be discussed herein, thisis achieved, in part, by dynamically loading and analyzing code modulesreferenced in the source code document (and any code modules referenceddirectly or indirectly by such code modules) while the user is editingit.

As also discussed above in the Background Section, providing accuratecode completion information for dynamic languages such as JavaScript canbe difficult since such languages do not provide a consistent objectmodel. Consequently, techniques such as token-based parsing and staticcode analysis may not be sufficient to correctly infer the shape andstructure of dynamic programming language entities such as variables,methods and the like, since these entities may be modified at runtime.This issue arises when trying to provide code completion information forcode modules programmed in a dynamic programming language such asJavaScript. As will be discussed herein, to address this issue,embodiments execute dynamically-loaded code modules in a partial codeevaluator to obtain information about dynamic programming languageentities that would otherwise only be available at runtime. The resultsof this partial code evaluation are then used to provide code completioninformation for the code modules.

It is desirable to provide code completion services in a manner thatdoes not adversely impact the responsiveness of the source code editor.However, a code module may itself be very large and/or incorporate anynumber of other code modules, which themselves may be very large.Consequently, performing a partial code evaluation of the code module(s)referenced by a source code document may be a time-consuming andresource-intensive task. To ensure that this task is performed in amanner that does not significantly impact editor performance,embodiments described herein perform the partial code evaluation of codemodules on a background thread that is separate from a main thread usedto execute the user interface for the source code editor. Also, resultsgenerated by performing partial code evaluation on core modules arestored in a cache so that they can be re-used to obtain code completioninformation, thereby avoiding having to perform partial code evaluationon the same code module more than once. Such cached partial codeevaluation results may also be used to derive code completioninformation for multiple source code documents being edited within thesame or different or source code editors. Furthermore, for core codemodules associated with a programming platform (e.g., core node.jsmodules), partial code evaluation results may be obtained offline,stored to disk, and then accessed to obtain code completion informationwhen such core code modules are incorporated into a source codedocument, thereby reducing the number of code modules that must bedynamically-loaded and evaluated while the source code editor isrunning.

Some exemplary implementations will now be described to help illustratethe foregoing features. In particular, Section II, below, describes anexample system for providing code completion features for a code modulereferenced by a source code document, as well as example methods forperforming the same function. Section III, below, describes an exampleprocessor-based computer system that may be used to implement certainfeatures described herein. Section IV provides some concluding remarks.

II. Example System and Methods for Providing Code Completion Featuresfor a Code Module Referenced by a Source Code Document

FIG. 1 depicts a block diagram of a system 100 that provides codecompletion features for a code module referenced by a source codedocument in accordance with an embodiment. It is noted that system 100is described herein by way of example only. Persons skilled in therelevant art(s) will readily appreciate that the techniques describedherein for providing code completion features for code modulesreferenced by source code documents may be implemented in a wide varietyof systems other than system 100 of FIG. 1.

As shown in FIG. 1, system 100 includes a source code editor 102, a codecompletion engine 104, a programming language engine 106, and a numberof components collectively designated programming platform support 108.In one embodiment, each of these components comprises software that isexecuted by the same processor-based computer system. One example of aprocessor-based computer system that may be used to execute thesecomponents is described in Section III below. In alternate embodiments,the components of system 100 may be distributed across two or moreprocessor-based computer systems. In accordance with such an alternateembodiment, information may be shared between the different componentsusing suitable interconnections or communication links as would beunderstood by persons skilled in the relevant art(s).

Source code editor 102 comprises a text editor that enables a userthereof to create and edit the source code of a computer program. Toachieve this, source code editor includes a user interface 112. Byinteracting with user interface 112, a user of source code editor 102can create a new source code document, open an existing source codedocument, edit a source code document, and save a source code document.After a user has created or opened a source code document, userinterface 112 will accept text input by the user into the source codedocument and display such text within the context of the source codedocument.

Source code editor 102 is communicatively connected to code completionengine 104. Code completion engine 104 is configured to generate andpresent code completion information for a source code document currentlybeing edited by a user of source code editor 102. Generally speaking,the code completion information comprises information about one or moreprogramming language entities (also referred to herein as “codeentities”) that may be of interest to a user of source code editor 102.Such information is presented to the user while the user is inputtingcode into user interface 112 and may be presented in a variety of forms.

By way of example, the code completion information may be presented aspart of a “list members” feature. The “list members” feature displays alist of valid member variables or functions for a particular class,struct, union or namespace after the user has typed a particular triggercharacter within the source code document. By interacting with aparticular member from the list, a user may cause the member to beautomatically inserted into the source code document or may receiveadditional information about the member.

As another example, the code completion information may be presented aspart of a “parameter list” feature. The “parameter list” featuredisplays information about the number, names, and types of parametersrequired by a function or attribute. Such information may be displayed,for example, after the user types the name of the function or attributefollowed by an open parenthesis.

As yet another example, the code completion information may be presentedas part of a “quick info” feature. The “quick info” feature displays acomplete declaration for a selected identifier within the source codedocument.

As still another example, the code completion information may bepresented as part of a “complete word” feature. The “complete word”feature automatically inputs the rest of a variable, command, orfunction name into a source code document once a user has entered enoughcharacters to disambiguate the term. If a number of variable, command orfunction names are potential matches, then a list of names will bepresented to the user and the user may select one for input.

The foregoing code completion features are presented by way of exampleand are not intended to be limiting. Persons skilled in the relevantart(s) will appreciate that code completion engine 104 may provide otherforms of code completion information other than those described above.

In an embodiment, code completion engine 104 is configured to providecode completion information for source code documents coded in aparticular programming language. For example, code completion engine 104may be configured to provide code completion information for source codedocuments coded in JavaScript. In accordance with such an embodiment,code completion engine 104 may comprise one of a plurality of codecompletion engines within system 100 and may be selectively invoked bysource code editor 102 based upon the type of source code document thatis being edited.

Generally speaking, code completion engine 104 generates code completioninformation by analyzing the contents of a source code document beingedited by a user of source code editor 102 while the user is editing it.Such analysis may comprise a combination of a token-based analysis,static code analysis and an analysis based on partial code evaluation.Such code completion information may be generated automatically based onwhat a user has typed or in response to an explicit user request. Oncethe code completion information has been generated, it is provided tosource code editor 102 for display to the user via user interface 112.

Partial code evaluation is utilized by code completion engine 104 toobtain information about dynamic programming language entities thatmight otherwise only be available at runtime. To enable such partialcode evaluation, code completion engine 104 is communicatively coupledto programming language engine 106. Programming language engine 106 isconfigured to perform operations that are specific to a particularprogramming language. For example, in one embodiment, programminglanguage engine 106 comprises a JavaScript engine that is configured toperform operations that are specific to a JavaScript programminglanguage.

As shown in FIG. 1, programming language engine 106 comprises aprogramming language parser 122, an abstract syntax tree 124, and apartial code evaluator 126. Programming language parser 122 isconfigured to analyze the text of a source code document currently beingedited within source code editor 102 to identify programming languageentities included therein and to represent such programming languageentities within a tree-like data structure, which is abstract syntaxtree 124. For example, in an embodiment in which programming languageengine 106 comprises a JavaScript engine, programming language parser122 analyzes the text of a JavaScript document currently being editedwithin source code editor 102 to identify JavaScript entities includedtherein and to represent such JavaScript entities within abstract syntaxtree 124.

Partial code evaluator 126 is configured to partially execute (orpseudo-execute) the code represented by abstract syntax tree 124 toobtain information about such code that would normally only be availableat runtime. The results of the partial code evaluation are madeaccessible to code completion engine 104 and code completion engine 104derives code completion information therefrom. In one embodiment,partial code evaluator 126 stores the partial code evaluation resultswithin the nodes of abstract syntax tree 124.

It is possible that a user of source code editor 102 may incorporate acode module into a source code document that he/she is editing. Suchcode module may comprise a code module associated with a particularprogramming platform and may be stored in a support library associatedwith such programming platform. By way of example, a user of source codeeditor 102 may incorporate a node.js module that is associated with thenode.js programming platform and that is stored in a node.js supportlibrary. Such node.js module may be incorporated, for example, by usingthe following JavaScript code:

var x=require (“everyauth”);

Such code has the effect of incorporating the node.js module “everyauth”and making it accessible via the variable x. It is to be understood thatthe contents of the incorporated code module are not actually part ofthe source code document—rather, the contents of the incorporated codemodule will be linked to the code of the source code document at runtimeby virtue of the statement of incorporation.

After incorporating the code module into the source code document, theuser of source code editor 102 may want to input code that referencesone or more code entities within the incorporated code module. Forexample, the user of source code editor 102 may wish to reference avariable, command, or function from the incorporated code module withinthe source code document. Furthermore, the user of source code editor102 may want to determine what parameters are required by a particularattribute or function from the incorporated code module, so that theycan properly utilize such attribute or function in the source codedocument.

To assist the user in this regard, system 100 is configured to providecode completion information to the user about the code entities withinthe incorporated code module, even though the contents of suchincorporated code module are not actually a part of the source codedocument being edited by the user. To achieve this, programming languageengine 106 is configured to utilize functionality provided by thecomponents of programming platform support 108 to dynamically load andapply partial code evaluation to code modules incorporated into thesource code document (as well as code modules referenced directly orindirectly by such code modules) while the user is editing it. Theresults of the partial code evaluation of the code modules are thenutilized by code completion engine 104 to derive code completioninformation therefrom.

In particular, when programming language engine 106 determines that acode module has been incorporated into the source code document beingedited by the user and that code completion information is required forat least one code entity associated with the code module, thenprogramming language engine 106 invokes a code module locator 132 todetermine a location of one or more files that include the contents ofthe code module. After the location of the file(s) has been determined,a code module loader 134 is invoked to load the contents of the file(s)located by code module locator 132. After the module code is loaded,such module code is processed by programming language parser 122, whichcreates an abstract syntax tree representation of the module code. Theabstract syntax tree representation of the module code is then passed topartial code evaluator 126, which performs partial code evaluation onthe abstract tree representation of the module code, thereby producingpartial code evaluation results. Partial code evaluator 126 then storesthe partial code evaluation results in a code module cache 136, wherethey can be accessed by code completion engine 104 to derive codecompletion information for the code module. In one embodiment, storingthe partial code evaluation results in code module cache 136 comprisesstoring the abstract syntax tree representation of the module code incode module cache 136 and then storing the partial code evaluationresults in the nodes of the abstract syntax tree representation.

In one embodiment, programming language engine 106 invokes code moduleloader 132 to load not only the code of the incorporated code module butalso the code of any code module referenced directly or indirectly bythe incorporated code module. Such code may also be partially evaluatedin the manner described above, and the partial evaluation resultsgenerated thereby may also be stored in code module cache 136.

In an embodiment, the partial code evaluation of the dynamically-loadedmodule code is performed in a background thread that is separate from amain thread that is used to execute user interface 112 of source codeeditor 102. This helps to ensure that such partial code evaluation willnot significantly impact the performance of source code editor 102.

As noted above, results generated by performing partial code evaluationon the module code are stored in code module cache 136. These cachedresults can be used repeatedly by code completion engine 104 to obtaincode completion information, thereby avoiding having to perform partialcode evaluation on the same code module more than once. Such cachedpartial code evaluation results may also be used to derive codecompletion information for multiple source code documents being editedwithin source code editor 102 or within a different source code editorentirely.

In a further embodiment, for core code modules associated with aprogramming platform (e.g., core node.js modules), partial codeevaluation results are obtained offline and stored to disk. Whenprogramming language engine 106 determines that code completioninformation is required for such core code module, it accesses thepre-evaluated results from disk and stores such results in code modulecache 136. This has the beneficial effect of reducing the number of codemodules that must be dynamically-loaded and evaluated while source codeeditor 102 is running.

The foregoing features of system 100 will now be further described withrespect to FIG. 2. In particular, FIG. 2 depicts a flowchart 200 of amethod for providing code completion features for a code modulereferenced by a source code document that may be implemented by system100. Although the steps of flowchart 200 will be described withcontinued reference to the components of system 100 as described abovein reference to FIG. 1, the method is not limited to that embodiment.Persons skilled in the relevant art(s) will appreciate that the methodof flowchart 200 may be implemented using other components or systemsentirely.

As shown in FIG. 2, the method of flowchart 200 begins at step 202 inwhich a user of source code editor 102 inputs code into a source codedocument that references a code module. By way of example, the user maytype the following two lines of code:

var x=require (“everyauth”);

x.

As discussed above, the first line of code has the effect ofincorporating the node.js module “everyauth” and making it accessiblevia the variable x. The second line of code indicates that the user isreferencing the variable x. The period following “x” comprises a triggercharacter that indicates that code completion information is requiredfor variable x.

In decision step 204, in response to the user inputting code thatreferences the code module, programming language engine 106 invokes codemodule locator 132, which determines whether the code module is a coremodule or a custom module. In one embodiment, determining whether thecode module is a core module or a custom module comprises comparing thename of the code module to a list of core module names for a particularprogramming platform. If the name of the code module matches a name onthe list, then the code module is determined to be a core module.Otherwise, the code module is determined to be a custom module. The listof core module names may be stored in non-volatile storage (e.g., adisk) that is locally accessible to code module locator 132 or may beretrieved from a remote computer via a suitable interconnection orcommunication link depending upon the implementation.

If it is determined during decision step 204 that the code module is acore code module, then control flows to step 206. During step 206, codemodule loader 134 is invoked to load pre-generated partial codeevaluation results for the code module from disk. The pre-generatedpartial code evaluation results are obtained offline by pre-applyingpartial code evaluation to the code of the core code module. Suchpre-generated partial code evaluation results are then stored in codemodule cache 136.

After step 206, control flows to decision step 208, in which programminglanguage engine 106 determines whether the code module referencesadditional code modules. If the code module does not reference anyadditional code modules, then control flows to step 226. During step226, codes completion engine 104 derives code completion information forthe code module from the partial evaluation results stored in codemodule cache 136 and presents such code completion information to theuser of source code editor 102.

However, if programming language engine 106 determines during step 208that the code module references additional code modules, then controlflows back to decision step 204 so that each additional code module canbe processed in the same manner as the original code module. In thisway, every additional code module that is referenced directly orindirectly by the original code module will be processed by the methodof flowchart 200.

Returning now to decision step 204, if code module locator 132determines that the code module is a custom code module rather than acore code module, then control flows to step 210. During step 210, codemodule locator 132 determines the location of one or more files on diskthat store the contents of the custom code module. This step may entailutilizing one or more rules that are utilized by a programming platformruntime to determine the location of the file(s). For example, in anembodiment in which the custom code module comprises a custom node.jsmodule, this step may entail utilizing the same rules that are utilizedby the node.js runtime to determine the location of the file(s) thatincludes the code of the custom node.js module.

After step 210, control flows to step decision step 212. During decisionstep 212, code module locator 132 determines if partial code evaluationresults have already been cached for the custom code module in codemodule cache 136. If partial code evaluation results have already beencached, then control flows to decision step 208, the functionality ofwhich has been previously described.

However, if code module locator 132 determines during decision step 212that partial code evaluation results have not already been cached forthe custom code module in code module cache 136, then control flows tostep 214. During step 214, code module loader 134 is invoked to loadinto volatile memory the module code of the custom code from the disklocation(s) identified during step 210. At step 216, programminglanguage parser 122 modifies this module code to include additionalstatements that contain all data types that the custom code moduleexposes as public.

At step 218, programming language parser 122 parses the modified modulecode to generate an abstract syntax tree representation thereof. Thisabstract syntax tree representation of the module code is processed bypartial code evaluator 126 to generate partial code evaluation results.At step 220, the partial code evaluation results generated during step218 are cached by code module cache 136. As previously discussed, codecompletion engine 104 may use such cached partial code evaluationresults to derive code completion information. In one embodiment,partial code evaluator 126 stores the partial code evaluation resultswithin the nodes of the abstract syntax tree representation of themodule code, which itself is stored within code module cache 136.

Depending upon the implementation, code module cache 136 may store thepartial code evaluation results in volatile memory or non-volatilememory. If the partial code evaluation results are stored in volatilememory only, then it may be that such results may only be used togenerate code completion information for source code documents beingedited on the same machine upon which source code editor 102 is runningwhile source code editor 102 is running. However, if the partial codeevaluation results are stored in non-volatile memory, then it ispossible that such partial code evaluation results may also be used togenerate code completion information for source code documents beingedited at a later time and/or on a different machine entirely.

As shown in FIG. 2, steps 212, 214, 216, 218 and 220 are performed on abackground thread. Such background thread is intended to represent athread that is different from a main thread that is used to execute userinterface 112 of source code editor 102. As previously discussed, suchan implementation advantageously minimizes the impact of such processingon the responsiveness of user interface 112.

After step 220, control flows to decision step 208, the functionality ofwhich has been previously described. After step 220, control also flowsto step 222. During step 222, code module cache 136 begins monitoringfor changes to the file(s) on disk that store the contents of the customcode module that was evaluated in step 220. As shown at step 224, ifcode module cache 136 determines that changes have been made to thefile(s), then code module cache 136 will clear the cached partialevaluation results for the custom code module. Code module cache 136 isprogrammed to behave in this manner to ensure that the cached partialevaluation results reflect the code that is actually stored in thecustom code module file(s).

As shown in FIG. 2, the end result of the method of flowchart 200 isthat code completion information is provided in step 226. It should benoted, however, that in certain embodiments, a “timeout” feature isimplemented by system 100. In accordance with such a “timeout” feature,if it takes too long to perform the partial code evaluation necessary togenerate the required code completion information, then code completionengine 104 will not provide code completion information to the user, orwill provide only incomplete code completion information to the user.However, once the partial code evaluation of a code module has beeninitiated in the manner shown in FIG. 2, such partial code evaluationwill nevertheless be completed in the background and the resultsgenerated thereby will be stored in code module cache 136 such that theywill be available for future use.

FIG. 3 depicts a flowchart 300 of a method for performing partial codeevaluation in accordance with an embodiment. This description isprovided herein by way of illustration only and is not intended to belimiting. The method shown in FIG. 3 may be used to perform partial codeevaluation of the code within a source code document being edited by auser of source code editor 102 as well as to perform partial codeevaluation of a code module incorporated into a source code documentbeing edited by a user of source code editor 102. Although the steps offlowchart 300 will be described with continued reference to thecomponents of system 100 as described above in reference to FIG. 1, themethod is not limited to that embodiment. Persons skilled in therelevant art(s) will appreciate that the method of flowchart 300 may beimplemented using other components or systems entirely.

As shown in FIG. 3, the method of flowchart begins at step 302, in whichthe code to which partial code evaluation is to be applied is loadedfrom disk. In the case in which the code comprises code from a customcode module, this step may be performed by code module loader 134.

At step 304, the code loaded during step 302 is parsed and an abstractsyntax tree representation of the code is generated thereby. In anembodiment, this step is performed by programming language parser 122.

A description of steps 306, 308, 310, 312, 314, 316, 318, 320, 322, 324,326 and 328 of flowchart 300 will now be provided. In an embodiment,each of these steps is performed by partial code evaluator 126.

At step 306, a leaf node for which code completion information isrequired is identified within the abstract syntax tree generated duringstep 304. At step 308, the abstract syntax tree is traversed upward fromthe leaf node identified during step 306 to identify each node of thetree that must be evaluated in order to properly evaluate the leaf nodeidentified during step 306.

At step 310, starting from the top-most node identified during step 308,the abstract tree is traversed downward, evaluating the code at eachnode in a downward path to the leaf node identified during step 306.This process is shown as a loop beginning at step 312, in which the nextnode in the series of nodes to be evaluated is obtained.

From step 312, control flows to decision step 314. During decision step314, it is determined whether too much time has been spent performingthe partial code evaluation. This step may be performed, for example, bycomparing an amount of time that has elapsed since beginning the partialcode evaluation to a predetermined time limit. However, this example isnot intended to be limiting, and other techniques may be used todetermine whether too much time has been spent performing the partialcode evaluation.

If it is determined during decision step 314 that too much time has beenspent performing the partial code evaluation, then control flows to step326. During step 326, one or more default values are assigned to theleaf node for which code completion information is required. Forexample, the default value(s) that are assigned may be determined basedon a data type of a variable represented by the leaf node. In furtheraccordance with this example, if the variable is an integer, a defaultvalue of 0 may be assigned. In still further accordance with thisexample, if the variable is a string, then one or more default methodsfor a string may be assigned.

After step 326, control flows to step 328 at which the partial codeevaluation process is completed. After step 328, code completioninformation is provided based on the results of the partial evaluationprocess as shown at step 330. This step may be performed, for example,by code completion engine 104.

Returning now to decision step 314, if it is determined that too muchtime has not been spent performing the partial code evaluation, thencontrol flows to decision step 316. If it is determined during decisionstep 316 that the leaf node for which code completion information isrequired has been reached then control flows to step 328, thefunctionality of which has already been described. However, if it isdetermined during decision step 316 that the leaf node for which codecompletion information is required has not been reached, then controlflows to decision step 318.

During decision step 318, it is determined whether cached partialevaluation results are already available for the node that is currentlybeing evaluated. If it is determined during decision step 318 thatcached partial evaluation results are already available for the nodethat is currently being evaluated, then control flows to step 312, thefunctionality of which has already been described. However, if it isdetermined during decision step 318 that cached partial evaluationresults are not already available for the node that is currently beingevaluated, then control flows to decision step 320.

During decision step 320, it is determined if there are any leafelements used in the expression represented by the node that iscurrently being evaluated that must be evaluated. If so, then controlflows to step 308 and the process initiated there is performed in arecursive manner to evaluate such leaf element(s). However, if it isdetermined during decision step 320 that there are no leaf elements tobe evaluated, then control flows to step 322.

At step 322, the code of the node is evaluated using partial codeevaluation techniques. Such techniques may involve, for example,executing the code of the node in a manner that limits the amount oftime spent evaluating such code. For example, if the code to beevaluated includes a loop with many iterations, only a few iterations ofthe loop may be executed in order to obtain results more quickly. Stillother techniques may be used to limit the amount of time required toexecute the code.

After step 322, the results of the partial code evaluation of the codeperformed during step 322 are cached in the node (i.e., as part of theabstract syntax tree data structure created during step 304), as shownat step 324. After step 324, control flows to step 312, thefunctionality of which has already been described.

It is noted that the foregoing functionality of flowchart 300 includes a“timeout” provision by way of decision step 314. However, as previouslynoted, in an embodiment the partial code evaluation of code modules,once initiated, is carried out in the background until such partial codeevaluation is complete. In accordance with such an embodiment, when themethod of flowchart 300 is applied to a code module, the time limitapplied by decision step 314 may be assumed to be infinity (i.e., thereis no time limit).

III. Example Processor-Based System Implementation

FIG. 4 depicts an example processor-based computer system 400 that maybe used to implement various embodiments described herein. For example,system 400 may be used to execute system 100 as described above inreference to FIG. 1, as well as any components thereof. The descriptionof system 400 provided herein is provided for purposes of illustration,and is not intended to be limiting. Embodiments may be implemented infurther types of computer systems, as would be known to persons skilledin the relevant art(s).

As shown in FIG. 4, system 400 includes a processing unit 402, a systemmemory 404, and a bus 406 that couples various system componentsincluding system memory 404 to processing unit 402. Processing unit 402may comprise one or more processors or processing cores. Bus 406represents one or more of any of several types of bus structures,including a memory bus or memory controller, a peripheral bus, anaccelerated graphics port, and a processor or local bus using any of avariety of bus architectures. System memory 404 includes read onlymemory (ROM) 408 and random access memory (RAM) 410. A basicinput/output system 412 (BIOS) is stored in ROM 408.

System 400 also has one or more of the following drives: a hard diskdrive 414 for reading from and writing to a hard disk, a magnetic diskdrive 416 for reading from or writing to a removable magnetic disk 418,and an optical disk drive 420 for reading from or writing to a removableoptical disk 422 such as a CD ROM, DVD ROM, BLU-RAY™ disk or otheroptical media. Hard disk drive 414, magnetic disk drive 416, and opticaldisk drive 420 are connected to bus 406 by a hard disk drive interface424, a magnetic disk drive interface 426, and an optical drive interface428, respectively. The drives and their associated computer-readablemedia provide nonvolatile storage of computer-readable instructions,data structures, program modules and other data for the computer.Although a hard disk, a removable magnetic disk and a removable opticaldisk are described, other types of computer-readable storage devices andstorage structures can be used to store data, such as flash memorycards, digital video disks, random access memories (RAMs), read onlymemories (ROM), and the like.

A number of program modules may be stored on the hard disk, magneticdisk, optical disk, ROM, or RAM. These program modules include anoperating system 430, one or more application programs 432, otherprogram modules 434, and program data 436. In accordance with variousembodiments, the program modules may include computer program logic thatis executable by processing unit 402 to perform any or all of thefunctions and features of system 100 as described above in reference toFIG. 1, as well as any components thereof. The program modules may alsoinclude computer program logic that, when executed by processing unit402, performs any of the steps or operations shown or described inreference to flowchart 200 of FIG. 2 and flowchart 300 of FIG. 3.

A user may enter commands and information into system 400 through inputdevices such as a keyboard 438 and a pointing device 440. Other inputdevices (not shown) may include a microphone, joystick, game controller,scanner, or the like. In one embodiment, a touch screen is provided inconjunction with a display 444 to allow a user to provide user input viathe application of a touch (as by a finger or stylus for example) to oneor more points on the touch screen. These and other input devices areoften connected to processing unit 402 through a serial port interface442 that is coupled to bus 406, but may be connected by otherinterfaces, such as a parallel port, game port, or a universal serialbus (USB). Such interfaces may be wired or wireless interfaces.

A display 444 is also connected to bus 406 via an interface, such as avideo adapter 446. In addition to display 444, system 400 may includeother peripheral output devices (not shown) such as speakers andprinters.

System 400 is connected to a network 448 (e.g., a local area network orwide area network such as the Internet) through a network interface oradapter 450, a modem 452, or other suitable means for establishingcommunications over the network. Modem 452, which may be internal orexternal, is connected to bus 406 via serial port interface 442.

As used herein, the terms “computer program medium,” “computer-readablemedium,” and “computer-readable storage medium” are used to generallyrefer to storage devices or storage structures such as the hard diskassociated with hard disk drive 414, removable magnetic disk 418,removable optical disk 422, as well as other storage device or storagestructures such as flash memory cards, digital video disks, randomaccess memories (RAMs), read only memories (ROM), and the like. Suchcomputer-readable storage media are distinguished from andnon-overlapping with communication media (do not include communicationmedia). Communication media typically embodies computer-readableinstructions, data structures, program modules or other data in amodulated data signal such as a carrier wave. The term “modulated datasignal” means a signal that has one or more of its characteristics setor changed in such a manner as to encode information in the signal. Byway of example, and not limitation, communication media includeswireless media such as acoustic, RF, infrared and other wireless media.Embodiments are also directed to such communication media.

As noted above, computer programs and modules (including applicationprograms 432 and other program modules 434) may be stored on the harddisk, magnetic disk, optical disk, ROM, or RAM. Such computer programsmay also be received via network interface 450, serial port interface442, or any other interface type. Such computer programs, when executedor loaded by an application, enable computer 400 to implement featuresof embodiments of the present invention discussed herein. Accordingly,such computer programs represent controllers of the computer 400.

Embodiments are also directed to computer program products comprisingsoftware stored on any computer useable medium. Such software, whenexecuted in one or more data processing devices, causes a dataprocessing device(s) to operate as described herein. Embodiments of thepresent invention employ any computer-useable or computer-readablemedium, known now or in the future. Examples of computer-readablemediums include, but are not limited to storage devices and storagestructures such as RAM, hard drives, floppy disks, CD ROMs, DVD ROMs,zip disks, tapes, magnetic storage devices, optical storage devices,MEMs, nanotechnology-based storage devices, and the like.

In alternative implementations, system 100 may be implemented ashardware logic/electrical circuitry or firmware. In accordance withfurther embodiments, one or more of these components may be implementedin a system-on-chip (SoC). The SoC may include an integrated circuitchip that includes one or more of a processor (e.g., a microcontroller,microprocessor, digital signal processor (DSP), etc.), memory, one ormore communication interfaces, and/or further circuits and/or embeddedfirmware to perform its functions.

V. Conclusion

While various embodiments have been described above, it should beunderstood that they have been presented by way of example only, and notlimitation. It will be apparent to persons skilled in the relevantart(s) that various changes in form and details can be made thereinwithout departing from the spirit and scope of the invention. Thus, thebreadth and scope of the present invention should not be limited by anyof the above-described exemplary embodiments, but should be defined onlyin accordance with the following claims and their equivalents.

What is claimed is:
 1. A method for providing code completion featuresfor a source code document being edited by a user of a source codeeditor, comprising: determining that the user has entered a statement ofincorporation into the source code document that will cause a first codemodule that is not part of the source code document to be linked atruntime and that code completion information is required for at leastone code entity associated with the first code module; and in responseto the determining step, loading module code, the module code includingcode of the first code module, executing the loaded module code in apartial code evaluator to generate partial code evaluation results, theexecuting the loaded module code in the partial code evaluatorcomprising executing only a selected portion of the loaded module code,deriving the code completion information from the partial codeevaluation results, and providing the code completion information to theuser of the source code editor.
 2. The method of claim 1, wherein thefirst code module comprises a code module written in a dynamicprogramming language.
 3. The method of claim 2, wherein the first codemodule comprises a node.js module.
 4. The method of claim 1, whereinloading the module code comprises: determining a location of a file thatstores at least a portion of the first code module.
 5. The method ofclaim 1, wherein the module code includes code of the first code moduleand code of one or more additional code modules referenced directly orindirectly by the first code module.
 6. The method of claim 1, whereinexecuting the loaded module code in the partial code evaluatorcomprises: building an abstract syntax tree based upon the loaded modulecode; and evaluating nodes of the abstract syntax tree in the partialcode evaluator.
 7. The method of claim 1, further comprising: cachingthe partial code evaluation results; wherein deriving the codecompletion information comprises deriving the code completioninformation from the cached partial code evaluation results.
 8. Themethod of claim 7, wherein caching the partial code evaluation resultscomprises caching the partial code evaluation results in at least one ofvolatile memory and non-volatile memory.
 9. The method of claim 7,further comprising: clearing the cached partial code evaluation resultsin response to determining that a file that stores at least a portion ofthe first code module has changed.
 10. The method of claim 6, furthercomprising: utilizing the cached partial code evaluation results toderive code completion information for a second source code document.11. The method of claim 1, wherein the step of executing the module codein the partial code evaluator is executed on a background thread that isseparate from a main thread upon which an interface for the source codeeditor is executed.
 12. The method of claim 1, further comprising: whilethe module code is being executed in the partial code evaluator,providing code completion information to the user of the source codeeditor that is based upon one or more default values rather than uponthe partial code evaluation results.
 13. A computer program productcomprising a computer readable storage device having computer programlogic recorded thereon for enabling a processing unit to provide codecompletion features for a source code document being edited by a user ofa source code editor, the computer program logic comprising: firstcomputer program logic that, when executed by the processing unit,determines that the user has entered a statement of incorporation intothe source code document that will cause a code module that is not partof the source code document to be linked at runtime and that codecompletion information is to be obtained for at least one code entityassociated with the code module; and second computer program logic that,when executed by the processing unit, performs the following in responseto the determination: loads partial code evaluation results obtained bypre-applying partial code evaluation to code of the code module, thepre-applying the partial code evaluation to the code of the code modulecomprising executing only a selected portion of the code of the codemodule, derives the code completion information from the partial codeevaluation results, and provides the code completion information to theuser of the source code editor.
 14. The computer program product ofclaim 13, wherein the code module comprises a code module written in adynamic programming language.
 15. The computer program product of claim14, wherein the code module comprises a node.js module.
 16. A system,comprising: one or more processors; and a storage medium that storescomputer program logic that is executable by the one or more processors,the computer program logic comprising: a programming language enginethat, in response to a determination that a user has entered a statementof incorporation into a source code document that will cause a firstcode module that is not part of the source code document to be linked atruntime and that code completion information is to be obtained for atleast one code entity associated with the first code module: determineswhether the first code module is a core module or a custom module; inresponse to determining that the first code module is a core module,obtains from a module loader partial code evaluation results obtained bypre-applying partial code evaluation to code of the first code module,the pre-applying the partial code evaluation to the code of the firstcode module comprising executing only a selected portion of the code ofthe first code module, and derives the code completion information fromthe partial code evaluation results obtained by pre-applying partialcode evaluation to the code-of the first code module; and in response todetermining that the first code module is a custom module, obtains fromthe module loader module code, the module code including code of thefirst code module, executes the module code in a partial code evaluatorto generate partial code evaluation results, the executing the modulecode in the partial code evaluator comprising executing only a selectedportion of the module code, and derives the code completion informationfrom the partial code evaluation results obtained by executing themodule code in the partial code evaluator; and a code completion enginethat provides the code completion information to the user of the sourcecode editor.
 17. The system of claim 16, wherein the first code modulecomprises a code module written in a dynamic programming language. 18.The system of claim 17, wherein the code module comprises a node.jsmodule.
 19. The system of claim 16, wherein the module code comprisescode of the first code module and code of one or more additional codemodules referenced directly or indirectly by the first code module. 20.The system of claim 16, wherein the computer program logic furthercomprises: a cache that caches the partial code evaluation resultsobtained by executing the module code in the partial code evaluator.